package com.yt.order.api.client;

import com.yt.common.constant.Result;
import com.yt.order.service.FastDFSService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/file")
@Api(value = "FileController", tags = "文件上传接口")
public class FileController {

    @Resource
    private FastDFSService fastDFSService;

    @PostMapping("/upload")
    @ApiOperation(value = "上传文件到FastDFS", notes = "返回文件访问URL")
    public Result<String> uploadFile(@RequestParam("file") MultipartFile file) {
        return fastDFSService.uploadFile(file);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "从FastDFS删除文件", notes = "通过文件URL删除文件")
    public Result<Void> deleteFile(@RequestParam("fileUrl") String fileUrl) {
        return fastDFSService.deleteFile(fileUrl);
    }
}